from django.db import models
from dvadmin.utils.serializers import CustomModelSerializer
from dvadmin.utils.models import CoreModel, SoftDeleteModel
from dvadmin.utils.viewset import CustomModelViewSet
from rest_framework.viewsets import ModelViewSet

# drf专用过滤器模块
from django_filters import rest_framework as filters


class Hanqiang(CoreModel):

    han_qiang_she_bei_bian_hao = models.TextField(verbose_name="焊枪设备编号", blank=True, null=True)
    han_qian_xing_hao = models.TextField(verbose_name="焊钳型号", blank=True, null=True)
    han_ji = models.TextField(verbose_name="焊机", blank=True, null=True)
    gui_fan = models.TextField(verbose_name="规范", blank=True, null=True)
    han_jie_1_dian_liu_kA = models.TextField(verbose_name="焊接1电流(kA)", blank=True, null=True)
    han_jie_1_shi_jian_ms = models.TextField(verbose_name="焊接1时间(ms)", blank=True, null=True)
    han_jie_2_dian_liu_kA = models.TextField(verbose_name="焊接2电流(kA)", blank=True, null=True)
    han_jie_2_shi_jian_ms = models.TextField(verbose_name="焊接2时间(ms)", blank=True, null=True)
    mai_chong_shu = models.TextField(verbose_name="脉冲数", blank=True, null=True)
    han_jie_ya_li_N = models.TextField(verbose_name="焊接压力(N)", blank=True, null=True)


    class Meta:
        db_table = 'station_weldspot_hanqiang'


class HanqiangModelSerializer(CustomModelSerializer):    
    class Meta:
        model = Hanqiang
        fields = '__all__'


class HanqiangFilter(filters.FilterSet):
    han_qiang_she_bei_bian_hao = filters.CharFilter(field_name='han_qiang_she_bei_bian_hao', lookup_expr='icontains')
    han_dian_bian_hao = filters.CharFilter(field_name='han_dian_bian_hao', lookup_expr='icontains')
    han_ji = filters.CharFilter(field_name='han_ji', lookup_expr='icontains')
    han_jie_ya_li_N = filters.CharFilter(field_name='han_jie_ya_li_N', lookup_expr='icontains')
    class Meta:
        models = Hanqiang
        fields = '__all__'


class HanqiangViewSet(CustomModelViewSet):
    values_queryset= Hanqiang.objects.all()
    serializer_class = HanqiangModelSerializer
    filter_class = HanqiangFilter